﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DotNetCore.BannerManagement.Domain;
using DotNetCore.BannerManagement.Domain;
using Microsoft.Practices.Repository;
using System.Globalization;
using System.Data.SqlClient; 


namespace DotNetCore.BannerManagement.DAL.Domain.dnc_ZoneRepositoryArtifacts
{
    /// <summary>
    /// This factory class takes a dnc_Zone object and generates
    /// the dbcommand object needed to call the underlying update
    /// stored proc.
    /// </summary>
    internal class dnc_ZoneUpdateFactory : IDbToBusinessEntityNameMapper, IUpdateFactory<dnc_Zone>
    {
        /// <summary>
        /// Creates the dnc_ZoneUpdateFactory to build an update statement for
        /// the given dnc_Zone object.
        /// </summary>
        public dnc_ZoneUpdateFactory()
        {
        }
        
        #region IUpdateFactory<dnc_Zone> Members

        public DbCommand ConstructUpdateCommand(Database db, dnc_Zone dnc_Zone)
        {
			DbCommand command = db.GetStoredProcCommand("Updatednc_Zone");
			
			    db.AddInParameter(command, "iD", DbType.Int32, dnc_Zone.ID);
			if(dnc_Zone.Name == null)
            {
                db.AddInParameter(command, "name", DbType.String);
            }
            else
            {
			    db.AddInParameter(command, "name", DbType.String, dnc_Zone.Name);
            }

			    db.AddInParameter(command, "zoneImageId", DbType.Int32, dnc_Zone.ZoneImageId);
			return command;
        }
        #endregion
        
		#region IDbToBusinessEntityNameMapper Members
        /// <summary>
        /// Maps a field name in the database (usually a parameter name for a stored proc)
        /// to the corresponding business entity property name.
        /// </summary>
        /// <remarks>This method is intended for error message handling, not for reflection.</remarks>
        /// <param name="dbParameter">Name of field/parameter that the database knows about.</param>
        /// <returns>Corresponding business entity field name.</returns>
        public string MapDbParameterToBusinessEntityProperty(string dbParameter)
        {
            switch (dbParameter)
            {
				case "iD":
					return "ID";
				case "name":
					return "Name";
				case "zoneImageId":
					return "ZoneImageId";
				default:
					throw new Exception(dbParameter);
			}
        }
        #endregion        
    }
}

